#ifndef		___DATA_SESSION_IMP___
#define		___DATA_SESSION_IMP___


#include "Message/MsgBuffer.h"
#include "Message/MsgIf.h"


class TCOM_API Session
{
public:
	Session(boost::asio::io_service &svcIO);

	int		getID()const;
	void	setID(int nID);

	int		getSID()const;
	void	setSID(int nID);

	virtual bool read(MsgBuffer* pBuffer = NULL);
	virtual bool write(MsgBuffer* pBuffer);
	virtual bool write(IMsg* pMsg);

	virtual bool onUpdate(const int& nElapse);

	virtual void onInput(const boost::system::error_code& error, size_t bytes_transferred, MsgBuffer* pBuffer );
	virtual void onOutput(const boost::system::error_code& error, size_t bytes_transferred, MsgBuffer* pBuffer );

	boost::asio::ip::tcp::socket& getSocket();

	void	setDataStreamPool(MsgBufferFactory* pMsgBuffFact);
protected:
	int	m_nSesId;	//	session id
	int m_nEttId;	//	entity	id

	boost::asio::ip::tcp::socket	m_theSocket;
	boost::asio::io_service&		m_theSvcIO;

	MsgBufferFactory*			m_wpMsgBufferFactory;
};

typedef stdext::hash_map<int, Session*>	DataSessionMap;

#endif